<?php
/**
 * @package TechStorm-Javascript
 * @version 1.0
 */
/*
Plugin Name: techstorm-javascript
Plugin URI: http://facebook.com/techstormteam
Description: This plugin will help you to put param to your javascript file
Version: 1.0
Author URI: http://facebook.com/techstormteam
*/

add_action( 'admin_menu', 'add_admin_menu' );

function add_admin_menu(){
     add_options_page( 'My Plugin', 'My Plugin', 'manage_options', 'my-plugin', 'my_options_page' );
}
add_action( 'admin_init', 'my_admin_init' );
function my_admin_init() {
    register_setting( 'my-settings-group', 'my-one-setting' );
    register_setting( 'my-settings-group', 'my-two-setting' );
    add_settings_section( 'section-one', 'Variable Section', 'section_one_callback', 'my-plugin' );
    add_settings_field( 'field-one', 'Domain', 'field_one_callback', 'my-plugin', 'section-one' );
    add_settings_field( 'field-two', 'Key', 'field_two_callback', 'my-plugin', 'section-one' );
}

function section_one_callback() {
    echo 'Some settings fields.';
}
function field_one_callback() {
    $setting = esc_attr( get_option( 'my-one-setting' ) );
    echo "<input type='text' name='my-one-setting' value='$setting' />";
}
function field_two_callback() {
    $setting = esc_attr( get_option( 'my-two-setting' ) );
    echo "<input type='text' name='my-two-setting' value='$setting' />";
}
function my_options_page() {
    ?>
    <div class="wrap">
        <h2>My Plugin Options</h2>
        <form action="options.php" method="POST">
            <?php settings_fields( 'my-settings-group' ); ?>
            <?php do_settings_sections( 'my-plugin' ); ?>
            <?php submit_button(); ?>
        </form>
    </div>
    <?php
}


function add_this_script_footer(){ 
    $domain = get_option('my-one-setting');
    $key = get_option('my-two-setting');
    
    global $current_user;
    get_currentuserinfo();
    $email = $current_user->user_email;
?>
<script type="text/javascript">
var _ta = _ta || [];
_ta.push(['domain', '<?php echo $domain; ?>']);
_ta.push(['key', '<?php echo $key ?>']);

// If email is there
_ta.push('email', '<?php echo $email ?>');	
</script>
<?php 
} 

add_action('wp_footer', 'add_this_script_footer'); 
?>